package model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.et.ar.ActiveRecordBase;
import com.et.ar.annotations.Column;
import com.et.ar.annotations.Id;
import com.et.ar.annotations.Table;
import com.et.ar.exception.ActiveRecordException;
import com.wzzz.cache.CacheHandler;
import com.wzzz.cache.CompanyCacheHandler;

@Table(name = "T_CASE_ROOM_INFO")
public class CaseRoomInfo extends ActiveRecordBase {
	@Id
	private String room_id; // 保管室ID
	@Column
	private String room_num; // 保管室编号
	@Column
	private String room_name; // 保管室名称
	@Column
	private String room_location; // 保管室位置
	@Column
	private String room_company; // 保管室所属单位
	@Column
	private String room_man; // 保管室负责人
	@Column
	private String room_tel; // 保管室联系电话
	@Column
	private String room_begin_date; // 保管室启用时间
	@Column
	private String room_status; // 保管室使用状态
	@Column
	private String room_coments; // 保管室备注信息

	public String getRoom_id() {
		return room_id;
	}

	public void setRoom_id(String room_id) {
		this.room_id = room_id;
	}

	public String getRoom_num() {
		return room_num;
	}

	public void setRoom_num(String room_num) {
		this.room_num = room_num;
	}

	public String getRoom_name() {
		return room_name;
	}

	public void setRoom_name(String room_name) {
		this.room_name = room_name;
	}

	public String getRoom_location() {
		return room_location;
	}

	public void setRoom_location(String room_location) {
		this.room_location = room_location;
	}

	public String getRoom_company() {
		return room_company;
	}
	public String getRoom_companyDesc() {
		return CompanyCacheHandler.getCompanyNameByID(room_company);
	}

	public void setRoom_company(String room_company) {
		this.room_company = room_company;
	}

	public String getRoom_man() {
		return room_man;
	}

	public void setRoom_man(String room_man) {
		this.room_man = room_man;
	}

	public String getRoom_tel() {
		return room_tel;
	}

	public void setRoom_tel(String room_tel) {
		this.room_tel = room_tel;
	}

	public String getRoom_begin_date() {
		return room_begin_date;
	}

	public void setRoom_begin_date(String room_begin_date) {
		this.room_begin_date = room_begin_date;
	}
	
	public String getRoom_status() {
		return room_status;
	}

	public String getRoom_statusDesc() {
		
		if(room_status != null){
			return CacheHandler.getDicDesc("10",room_status);
		}
		return room_status;
	}

	public void setRoom_status(String room_status) {
		this.room_status = room_status;
	}

	public String getRoom_coments() {
		return room_coments;
	}

	public void setRoom_coments(String room_coments) {
		this.room_coments = room_coments;
	}
	//删除前检查所属保险室是有有有效的保险柜，如果有就不能删除
	@Override
	public void beforeDestroy() throws ActiveRecordException {
		//查看当前单位下是否有预打印的条形码
		
		StringBuffer sql= new StringBuffer();
		sql.append("SELECT COUNT(1) CNT \n" );
		sql.append("  FROM T_CASE_SHELF_INFO T\n" );
		sql.append(" WHERE T.SHELF_STATUS = 1\n" );
		sql.append("   AND T.CASE_ROOM_ID ="+this.room_id);
		String count = "0";
		List<Map<String, Object>> list = CommonInfo.getResultMap(CommonInfo.class, sql.toString(),null, "",0,Integer.MAX_VALUE);
		for(int i=0;i<list.size();i++){
			HashMap<String, Object> allMap = (HashMap<String, Object>)list.get(i);
			count = allMap.get("cnt").toString();
//			System.out.println(allMap.get("goods_kind")+"---"+allMap.get("note"));
//			CACHE_KIND_NAME.put(allMap.get("goods_kind").toString(), allMap.get("note").toString());
		}
		
		if(!"0".equals(count)){//说明存在
			throw new ActiveRecordException("");
		}
	}
}
